package org.ziwei.rule.impl;

import java.util.ArrayList;
import java.util.List;

import org.ziwei.paipan.Gong;
import org.ziwei.paipan.MingPan;
import org.ziwei.paipan.Star;
import org.ziwei.paipan.var.StarCode;
import org.ziwei.rule.api.RuleHandler;
import org.ziwei.rule.util.RuleUtils;

/**
 * 紫微坐命
 */
public class ZiWeiZuoMing implements RuleHandler{
	
	private List<String> ruleCodes;
	
	private MingPan mingPan;
	
	@Override
	public List<String> fireRule(MingPan pan) throws Exception {
		ruleCodes = new ArrayList<String>();
		mingPan = pan;
		
		List<Star> stars = RuleUtils.mingGongZhengYao(pan);
		boolean flag = false;
		for(Star star : stars){
			if(star.getStarCode() == StarCode.ZIWEI){
				flag = true;
				if(star.getSiHua() == StarCode.HUAQUAN){
					ruleCodes.add("ziweizuominghuaquan");
				}
			}
		}
		
		if(!flag){
			return ruleCodes;
		}
		
		ruleCodes.add("ziweizuomingzhangxiang");
		
		
		rule1();
		
		rule2();
		
		return ruleCodes;
	}

	private void rule1(){
		Gong gong = RuleUtils.mingGong(mingPan);
		List<Star> stars = RuleUtils.sanFangSiZheng(mingPan, gong);
		int count = 0;
		for(Star star : stars){
			StarCode sc = star.getStarCode();
			if(sc == StarCode.TIANFU || sc == StarCode.LUCUN || sc == StarCode.TIANMA){
				count++;
			}
		}
		if(count == 3){
			ruleCodes.add("ziweizuomingtianfulucuntianma");
		}
	}
	
	private void rule2(){
		//百官朝拱
		Gong gong = RuleUtils.mingGong(mingPan);
		List<Star> stars = RuleUtils.baiGuanChaoGong(mingPan, gong);
		if(stars.size() >= 4){
			ruleCodes.add("ziweizuomingbaiguanchaogong");
		}else{
			ruleCodes.add("ziweizuomingwubaiguanchaogong");
		}
	}
}
